<?php
namespace App\Repositories\GameServer;

use App\Models\GameServer\Email;

class EmailRepository
{
    //获取邮件列表
    public function getEmails()
    {
        $emails = Email::whereIn('receiver_account_id', ['0','-1','-2'])
                        ->select('id','sender_account_name','receiver_account_id', 'title', 'content','published_at')
                        ->orderBy('id', 'desc')
                        ->get();
        // dd($emails);
        return $emails;
    }

    public function getEmail($id)
    {
        return Email::findOrFail($id);
    }

    public function addEmail($request)
    {
        $email = Email::create([
            'sender_account_id' => 0,
            'sender_account_name' => session('admin')->user_name,
            'receiver_account_id' => $request->receiver_account_id,
            'receiver_account_name' => '',
            'title' => $request->title,
            'content' => $request->content,
            'published_at' => $request->published_at
        ]);
        return $email;
    }

    public function updateEmail($request, $id)
    {
        $request->unread = 1;
        return Email::find($id)->update($request->all());
    }

    public function deleteEmail($id)
    {
        return Email::destroy($id);
    }

    public function destroyList($ids)
    {
        return Email::destroy($ids);
    }


}